import sympy as sp

#最小二乘法求极值
x = sp.symbols('x')
y = sp.symbols('y')

f = x ** 2 + y ** 2 - 2 * x * y
deritative = sp.diff(f,x)
deritative1 = sp.diff(f,y)
print(deritative)
print(deritative1)
result = sp.solve(deritative,x)
result1 = sp.solve(deritative1,y)
# result2 = sp.solve((deritative,deritative1),(x,y))
print(result)
print(result1)
# print(result2)
# print(f.subs(x,result[0]))
# print(f.subs(y,result1[0]))
# print(f.subs(result2))